﻿using HeadFirst._02.Observer.Observer.Interface;
using HeadFirst._02.Observer.Subjects.Interfaces;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;

namespace HeadFirst._02.Observer.Subjects.Implementations
{
    public class WeatherData : Subject
    {
        public static List<IObserverable> _observerList = new List<IObserverable>();

        public void NotifyObservers()
        {
            var temp = GetTemperature();
            var humidity = GetHumidity();
            var pressure = GetPressure();

            _observerList.ForEach(x => x.Update(temp, humidity, pressure));
        }

        public void RegisterObserver(IObserverable o)
        {
            if (o != null)
                _observerList.Add(o);

        }

        public void RemoveObserver(IObserverable o)
        {
            if (o != null)
                _observerList.Remove(o);
        }

        public double GetTemperature()
        {
            var random = new Random();
            return random.Next() % 30 + random.NextDouble();


        }
        public double GetHumidity()
        {

            var random = new Random();
            return random.Next() % 100 + random.NextDouble();

        }

        public double GetPressure()
        {

            var random = new Random();
            return random.Next() % 100 + random.NextDouble();

        }

        public void MeasurementsChanged()
        {
            NotifyObservers();
        }


    }
}
